//
// Created by Administrator on 2023/8/2.
//
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>

using namespace std;

class Solution {
public:
    vector<vector<int>> findMatrix(vector<int> &nums) {
        // 先统计出nums中各个数字有几个,出现最多的就是行数
        unordered_map<int, int> counter;
        int max_count = 0;
        for (auto &x: nums) {
            counter[x]++;
            max_count = max(max_count, counter[x]);
        }
        vector<vector<int>> result(max_count);
        for (auto &x: counter) {
            for (int i = 0; i < x.second; i++) {
                result[i].push_back(x.first);
            }
        }
        return result;
    }
};

int main() {
    Solution s;
    vector<int> nums = {1, 3, 4, 1, 2, 3, 1};
    vector<vector<int>> result = s.findMatrix(nums);
    for (int i = 0; i < result.size(); i++) {
        for (int j = 0; j < result[i].size(); j++) {
            cout << result[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}